<?php

namespace app\admin\controller;

use com\IpLocation;
 
class Log extends Common {

    /**
     * 操作日志
     * @return mixed|\think\response\Json
     */
    public function index() {

        $adminService = model("Admin","service");

        $adminList = $adminService->getAdminList();

        $logService = model("Log","service");

        $requestMap = $this->convertRequestToMap();

        $list = $logService->paginateList($requestMap);

        //实例化类参数表示IP地址库文件
        $ipLocation = new IpLocation('UTFWry.dat');

        foreach($list as $key=>$item){
            $item['add_time']=date('Y-m-d H:i:s',$item['add_time']);
            $item['ip_addr'] = $ipLocation->getlocation($item['ip']);
        }

        $this->assign("adminList",$adminList);
        $this->assign('list',$list);

        return $this->fetch();
    }

    /**
     * 日志删除操作
     * @return \think\response\Json
     */
    public function delete() {

        $id = input('param.id');

        $logService = model("Log","service");

        try {
            $result = $logService->deleteById($id);

            if(false === $result) {
                $this->error($logService->getError());
            }

            $this->success("日志删除成功");

        } catch(\PDOException $e) {
            $this->error($e->getMessage());
        }
    }
 
}